module ICarry {

    export class OfferViewModel implements PrismBreak.PbViewModel{

        private _app: ICarryApplication;
        private _view: PrismBreak.View;

        private nextToken: string;
        private previousToken: string;

        private note: KnockoutObservable<string>;
        private imageUploaded: KnockoutObservable<boolean>;
        constructor(app: PrismBreak.PbApp) {
            this._app = <ICarryApplication>app;

        }

        public Initialize(view: PrismBreak.View) {
            this._view = <PrismBreak.View> view;

            this.note = ko.observable("");
            this.imageUploaded = ko.observable(false);
            ko.applyBindings(this, view.Node);

        }

        public Activated() {
            //Start listening to next event
            this.nextToken = this._app.EventManager.Subscribe(PrismBreak.EventType[PrismBreak.EventType.RequestNextStep], () => {
                this.GoToNextStep();
            });

            this.previousToken = this._app.EventManager.Subscribe(PrismBreak.EventType[PrismBreak.EventType.RequestPreviousStep], () => {
                this.GoToPreviousStep();
            });
        }

        private GoToNextStep(): void {

            if (this.CanGoNext()) {
                //Stop listening to next event
                this._app.EventManager.Unsubscribe(PrismBreak.EventType[PrismBreak.EventType.RequestNextStep], this.nextToken);

                this._app.EventManager.Unsubscribe(PrismBreak.EventType[PrismBreak.EventType.RequestPreviousStep], this.previousToken);
                //activate next view

            }
        }

        private CanGoNext(): boolean {
            //TODO: do some validation
            return true;
        }

        private GoToPreviousStep(): void {

            if (this.CanGoPrevious()) {
                //Stop listening to previous event
                this._app.EventManager.Unsubscribe(PrismBreak.EventType[PrismBreak.EventType.RequestNextStep], this.nextToken);
                this._app.EventManager.Unsubscribe(PrismBreak.EventType[PrismBreak.EventType.RequestPreviousStep], this.previousToken);

                //activate previous view
                this._app.ViewManager.ActivateViewById("RequestOfferView");

            }
        }

        private CanGoPrevious(): boolean {
            //TODO: do some validation
            return true;
        }

        private ImageChanged(event: Event): void{

            console.log("Image changed");

        }

    }

}  